/**
 * 
 */
package cs3201.westga.edu.project_2;

/**
 * This is the Sphere class. A Sphere can be described by its radius.
 * @author Cody Stamps
 *
 */
public class Sphere {
	
	private double radius;
	
	
	/**
	 * Constructor for class Sphere
	 * @param radius
	 */
	public Sphere(double _radius) {
		setRadius(_radius);
	}
	
	/**
	 * getRadius() - returns the current radius of the Sphere
	 * @return the radius
	 */
	public double getRadius() {
		return radius;
	}
	
	/**
	 * setRadius() sets the Radius of the sphere
	 * @param radius the Radius to set
	 * @throws IllegalArgumentException  if the radius to be set is < 0
	 */
	public void setRadius(double radius) {
		//REQUIRES the Radius be greater than 0
		//MODIFIES radius
		//EFFECTS changes the radius
		if (radius <= 0 ){
			throw new IllegalArgumentException("Error: Invalid input. The Radius must be greater than 0.");
		}
		this.radius = radius;
	}
	
	
	
	/**
	 * hashCode() - generates a hashcode version of this sphere
	 * @return the hashcode version of this sphere
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		long temp;
		temp = Double.doubleToLongBits(radius);
		result = prime * result + (int) (temp ^ (temp >>> 32));
		return result;
	}

	/**
	 * equals() - test if an object is equal to this sphere
	 * @return - true if object is equal, else false.
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) //checks obj to this sphere
			return true; //if the same sphere return true.
		if (obj == null) //checks to make sure obj is not null
			return false; //if it is return false.
		if (getClass() != obj.getClass()) //checks to make sure obj's class is the same as this sphere
			return false; //if not return false.
		Sphere other = (Sphere) obj; //cast the obj as a sphere object.
		if (Double.doubleToLongBits(radius) != Double // checks to see if other's base is the same as this sphere base
				.doubleToLongBits(other.radius)) 
			return false; //if it is not, return false
		return true; //else return true.
	}

	/**
	 * toString() - returns a string representation of this sphere.
	 * @return - the string representation of this sphere. 
	 */
	@Override
	public String toString() {
		return "Sphere [radius=" + radius;
	}
	
	/**
	 * resize(double) - adjust the radius according to the amount.
	 * @param amount - the size to readjust by.
	 */
	public void resize(double amount){
		//REQUIRES The amount > 0
		//MODIFIES radius
		//EFFECTS The radius will be multiplied by the amount.
		if (amount <= 0){
			throw new IllegalArgumentException("Error: The amount by which you want to resize is invalid.");
		}
		radius = radius * amount;
		System.out.println("The radius is now: " + radius); 
	}
	
	/**
	 * getVolume() - calculates the volume of this sphere.
	 * @return - the volume of this sphere
	 */
	public double getVolume(){
		return ( 4.0 / 3.0 ) * Math.PI * Math.pow( radius, 3 );
	}

}
